package com.qf.controller;

import com.qf.pojo.Dept;
import com.qf.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpStatusCodeException;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping("/depts")
    public List<Dept> depts(){
        return deptService.findAll();
    }

    @PutMapping("/dept")
    public ResponseEntity<Dept> update(@RequestBody Dept dept){
         deptService.update(dept);
         return new ResponseEntity<Dept> (dept, HttpStatus.OK);
    }

    @PostMapping("/dept")
    public Dept addDept(@RequestBody Dept dept){
        Dept dept1 = deptService.add(dept);
        return dept1;
    }

    @DeleteMapping("/dept{id}")
    public ResponseEntity<Integer> delete(@PathVariable int id){
        deptService.delete(id);
        return new ResponseEntity<Integer> (200,HttpStatus.OK);
    }
}
